package net.sudot.chess.business.dto;

import lombok.Getter;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 错误响应信息
 *
 * @author tangjialin on 2019-01-23.
 */
@Getter
@Accessors(chain = true)
public class ErrorResponse implements Serializable {
    private static final long serialVersionUID = -1;
    private long timestamp = System.currentTimeMillis();
    private int status;
    private String error;
    private String message;
    private String path;

    public ErrorResponse(HttpStatus httpStatus, String path) {
        this(httpStatus, path, null);
    }

    public ErrorResponse(HttpStatus httpStatus, String path, String message) {
        this.status = httpStatus.value();
        this.error = httpStatus.getReasonPhrase();
        this.message = message;
        this.path = path;
    }

    public ErrorResponse setMessage(String message) {
        this.message = message;
        return this;
    }
}
